package com.chennan.redis.domain.number.impl;

import com.chennan.redis.domain.number.NumberEnum;
import com.chennan.redis.domain.number.NumberService;
import com.chennan.redis.domain.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @author chennan
 * @createTime 2021年07月26日 16:16:00
 */
@Service
public class NumberServiceImpl implements NumberService {

    @Autowired
    private RedisService redisService;

    @Override
    public BigDecimal getNextNumber(NumberEnum numberEnum) {
        Long incr = redisService.incr(numberEnum.getVal(), 1L);
        return new BigDecimal(incr);
    }

    @Override
    public BigDecimal getNextNumber(NumberEnum numberEnum, Long start) {
        Long incr = redisService.incr(numberEnum.getVal(), start);
        return new BigDecimal(incr);
    }
}
